import {useRoute} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import {View, Text, SafeAreaView} from 'react-native';
import {getUserInfo} from '../../api/home';
import Header from './Header';
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs';
import MainPage from '../../pages/mainpage';
import Dynamic from '../../pages/dynamic';
import {ScrollView} from 'react-native-gesture-handler';
import {Dimensions} from 'react-native';
const Tab = createMaterialTopTabNavigator();

const UserInfo = () => {
  const windowHeight = Dimensions.get('window').height;
  const param = useRoute();
  console.log(param);
  const [userProfile, setUserProfile] = useState({});
  const [isDisableScroll, setDisableScroll] = useState(true);
  useEffect(() => {
    // console.log('````')
    async function getInfo() {
      try {
        let res = await getUserInfo({uid: param.params.userid});
        let data = await res.json();
        // console.log(data)
        setUserProfile({...data});
        console.log(userProfile, 'ffff');
      } catch (e) {
        console.log(e);
      }
    }
    getInfo();
  }, []);
  return (
    <SafeAreaView style={{flex: 1}}>
      <ScrollView
        onScrollEndDrag={(e) => console.log(e.nativeEvent)}
        stickyHeaderIndices={[1]}
        style={{height: windowHeight - 90}}
        scrollEnabled={isDisableScroll}>
        {userProfile && userProfile.profile && (
          <Header {...userProfile.profile} style={{overflow: 'hidden'}} />
        )}
        <Tab.Navigator
          style={{top: -50, flex: 1}}
          sceneContainerStyle={{
            flex: 1,
          }}
          tabBarOptions={{
            activeTintColor: 'red',
            indicatorStyle: {
              borderBottomColor: 'red',
              backgroundColor: 'red',
            },
            // tabStyle: {width: 100},
            style: {
              borderTopLeftRadius: 20,
              borderTopRightRadius: 20,
              overflow: 'hidden',
            },
          }}>
          <Tab.Screen
            name="MainPage"
            component={MainPage}
            options={{title: '主页'}}
          />
          <Tab.Screen
            name="Dynamic"
            component={Dynamic}
            options={{title: '动态'}}
          />
        </Tab.Navigator>
      </ScrollView>
    </SafeAreaView>
  );
};

export default UserInfo;
